package com.wwwarehouse.contract.contract.info;

import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.wwwarehouse.common.bean.response.CommonClass;
import com.wwwarehouse.common.tools.rsa.StringUtils;
import com.wwwarehouse.contract.bean.InfoDeliverableItemBean;
import com.wwwarehouse.contract.contract.TheParentFragment;
import com.wwwarehouse.contract.core.ContractConstant;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import contract.wwwarehouse.com.contract.R;

/**
 * Created by feng.gao on 2017/11/3.
 * 交付项信息卡
 */

public class InfoCardDeliverItemFragment extends TheParentFragment {
	private TextView mSendTv;
	private TextView mPayTv;
	private RelativeLayout mSendRl;
	private RelativeLayout mPayRl;
	private String mContractUkid;
	private int REQUEST_DELIVER_ITEM_INFO_CODE = 1;
	@Override
	protected int getContentId() {
		return R.layout.info_card_deliver_item_fragment;
	}

	@Override
	public void setTitle() {
		mActivity.setTitle(R.string.contract_modify_info_card_deliverable_item_title);
	}

	@Override
	public void requestDatas() {
		if (getArguments() == null || StringUtils.isNullString(getArguments().getString(ContractConstant.KEY_MODIFY_PAYMENT_ITEM_CONTRACT_UKID))) {
			mLoadingView.showSystemView(true);
			mLoadingView.setSystemListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					requestDatas();
				}
			});
			return;
		}
		mContractUkid = getArguments().getString(ContractConstant.KEY_MODIFY_PAYMENT_ITEM_CONTRACT_UKID);
		Map<String, String> mParamsMap = new HashMap<>();
		mParamsMap.put("contractUkid", mContractUkid);
		httpPost(ContractConstant.METHOD_INFO_CARD_DELIVER_ITEM_CONTRACT ,mParamsMap ,REQUEST_DELIVER_ITEM_INFO_CODE );

	}

	@Override
	protected void init(View view) {
		mSendTv = (TextView) view.findViewById(R.id.send_tv);
		mSendRl = (RelativeLayout) view.findViewById(R.id.send_layout);
		mPayRl = (RelativeLayout) view.findViewById(R.id.pay_layout);
		mPayTv = (TextView) view.findViewById(R.id.pay_time);

	}

	@Override
	public void onSuccess(CommonClass commonClass, int what) {
		if (commonClass == null || commonClass.getData() == null || commonClass.getCode() == null) {
			return;
		}
		List<InfoDeliverableItemBean.DataBean> deliverableItemBean = JSON.parseArray(commonClass.getData().toString() , InfoDeliverableItemBean.DataBean.class);
		if (deliverableItemBean == null || deliverableItemBean.size() == 0) {
			mLoadingView.showEmptyView(true);
			mLoadingView.setEmptyListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					requestDatas();
				}
			});
			return;
		}
		if (StringUtils.isNoneNullString(deliverableItemBean.get(0).getPbDeliveryEarly()) && StringUtils.isNoneNullString(deliverableItemBean.get(0).getPbDeliveryLast())) {
			mSendRl.setVisibility(View.VISIBLE);
			mPayTv.setText(deliverableItemBean.get(0).getPbDeliveryEarly() + "天" + "-" + deliverableItemBean.get(0).getPbDeliveryLast() + "天");
		} else {
			mSendRl.setVisibility(View.GONE);
		}
		if (StringUtils.isNoneNullString(deliverableItemBean.get(0).getPbSendEarly()) && StringUtils.isNoneNullString(deliverableItemBean.get(0).getPbSendLast())) {
			mSendRl.setVisibility(View.VISIBLE);
			mSendTv.setText(deliverableItemBean.get(0).getPbSendEarly() + "天" + "-" + deliverableItemBean.get(0).getPbSendLast() + "天");
		}

	}

	@Override
	public void onReLoad(int code) {

	}
}
